﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DLSportsRecords
{
    public sealed class DLSportsRecords
    {
        #region Properties and Constructors
        /// <summary>
        /// Objecto para Base de Dados e propriedade para instanciar a classe a partir de classes exteriores.
        /// </summary>
        private SportRecordsEntities DataBase = new SportRecordsEntities();
        public static DLSportsRecords GetInstance { get { return DLSportsRecordsInstance.Instance; } }
        /// <summary>
        /// Classe para consumo interno para instancianr a mesma.
        /// </summary>
        private class DLSportsRecordsInstance
        {
            internal static readonly DLSportsRecords Instance = new DLSportsRecords();
            private DLSportsRecordsInstance() { }
        }
        private DLSportsRecords() { }
        #endregion

        #region Methods
        public List<Rank> GetRank()
        {
            try
            {
                return DataBase.Ranks.ToList();
            }
            catch (Exception ex)
            {
                InsertLog(new Log { Date = DateTime.Now, ErrorMsg = ex.Message.ToString() });
                throw ex;
            }
        }
        public Rank GetRankByRankId(int RankId)
        {
            return DataBase.Ranks.Where(r => r.RankId == RankId).Single();
        }
        public void InsertLog(Log log)
        {
            DataBase.Logs.AddObject(log);
            DataBase.SaveChanges();
        }
        #endregion

    }
}
